-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): new worker pkg #3979
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heiytor
force-pushed
the
feat/workers
branch
4 times, most recently
from
July 23, 2024 16:19
797f796
to
118ec01
Compare
heiytor
force-pushed
the
feat/workers
branch
5 times, most recently
from
July 24, 2024 20:43
ad9f36b
to
a3742cc
Compare
We're refactoring the old `api/workers` into a proper package under `pkg`. The new package includes two interfaces: `Server`, which registers for process events, and `Client`, which submits events. A server can listen for events by calling `HandleTask`. Cron jobs are also supported via `HandleCron`. Several structs and methods have been added to facilitate task and cron processing. The new `worker/asynq` package has been created to implement these interfaces. The package uses Asynq as the backend for the worker. Different implementations can be created to implement the interfaces. Example usage: ```go func main() { server := asynq.NewServer("...") defer server.Shutdown() server.HandleTask( "queue:kind", func(_ context.Context, payload []byte) error { fmt.Println("Executing task with payload "+string(payload)) return nil }, ) if err := server.Start(); err != nil { panic(err) } client, err := asynq.NewClient("...") if err != nil { panic(err) } defer client.Close() if err := client.Submit( context.Background(), "queue:kind", []byte("payload"), ); err != nil { panic(err) } os.Exit(0) } ```
heiytor
added a commit
that referenced
this pull request
Jul 25, 2024
The old `api/workers` has been removed in favor of the new worker package (#3979). The workers' initialization has also been moved to the `startServer` function to ensure proper shutdown within the router.
heiytor
added a commit
that referenced
this pull request
Jul 25, 2024
To support the new worker package, we are replacing the direct usage of `asynq.Client` with the new `worker.Client` (#3979). The client initialization process has also been updated to return an error if the worker cannot be created.
heiytor
added a commit
that referenced
this pull request
Jul 25, 2024
The old `api/workers` has been removed in favor of the new worker package (#3979). The workers' initialization has also been moved to the `startServer` function to ensure proper shutdown within the router.
heiytor
added a commit
that referenced
this pull request
Jul 25, 2024
To support the new worker package, we are replacing the direct usage of `asynq.Client` with the new `worker.Client` (#3979). The client initialization process has also been updated to return an error if the worker cannot be created.
gustavosbarreto
pushed a commit
that referenced
this pull request
Jul 26, 2024
The old `api/workers` has been removed in favor of the new worker package (#3979). The workers' initialization has also been moved to the `startServer` function to ensure proper shutdown within the router.
gustavosbarreto
pushed a commit
that referenced
this pull request
Jul 26, 2024
To support the new worker package, we are replacing the direct usage of `asynq.Client` with the new `worker.Client` (#3979). The client initialization process has also been updated to return an error if the worker cannot be created.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We're refactoring the old
api/workers
into a proper package underpkg
. The new package includes two interfaces:Server
, which registers for process events, andClient
, which submits events.A server can listen for events by calling
HandleTask
. Cron jobs are also supported viaHandleCron
. Several structs and methods have been added to facilitate task and cron processing.The new
worker/asynq
package has been created to implement these interfaces. The package uses Asynq as the backend for the worker. Different implementations can be created to implement the interfaces.Example usage: